﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Net;
using D3DSS.IDomain;
using StructureMap;

namespace D3DSS.IoC
{
    /// <summary>
    /// 加密服务请求验证类
    /// </summary>
    internal class SecureServiceAuthorizationManager : ServiceAuthorizationManager
    {
        protected IAccount AccountService;

        public SecureServiceAuthorizationManager()
            : base()
        {
            AccountService = ObjectFactory.GetInstance<IAccount>();
        }

        protected override bool CheckAccessCore(OperationContext operationContext)
        {
            var authorization = WebOperationContext.Current.IncomingRequest.Headers[HttpRequestHeader.Authorization];
            var response = AccountService.ProcessAuthorization(authorization);
            WebOperationContext.Current.OutgoingResponse.StatusCode = response.Data.StatusCode;
            return response.IsSuccess;
        }
    }
}
